package com.djq.hhc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.djq.hhc.mapper.HomeFamilyMapper;
import com.djq.hhc.mapper.HomeFlowerMapper;
import com.djq.hhc.model.home.HomeFamily;
import com.djq.hhc.model.home.HomeFlower;
import com.djq.hhc.result.Result;
import com.djq.hhc.service.HomeFamilyService;
import com.djq.hhc.service.HomeFlowerService;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: dadd7
 * @Date: 2023/03/05/下午 4:53
 * @Description:
 */

@Service
public class HomeFamilyServiceImpl extends ServiceImpl<HomeFamilyMapper, HomeFamily> implements HomeFamilyService {
    @Override
    public Result saveFamily(HomeFamily homeFamily) {
        String familyName = homeFamily.getFamilyName();
        HomeFamily one = query().eq("family_name", familyName).one();
        if (one == null) {
            save(homeFamily);
            return Result.ok().message("增加成功");
        } else {
            return Result.fail().message(familyName+"已存在");
        }
    }

    @Override
    public Result updateFamily(HomeFamily homeFamily) {
        Long id = homeFamily.getId();
        String familyName = homeFamily.getFamilyName();
        HomeFamily one = query().eq("family_name", familyName).ne("id", id).one();
        if (one == null) {
            updateById(homeFamily);
            return Result.ok().message("修改成功");
        } else {
            return Result.fail().message(familyName+"已存在");
        }
    }
}
